package club.sanmubird.travel_culture_wx_demo.demo.mysql.util;

import java.util.Arrays;

/**
 * @program: travel_culture_wx_demo
 * @description: 校验 微信的
 * @author: sam
 * @create: 2018-08-04 18:14
 * @update: 2018-08-04 18:14
 * @update: Sam
 **/
public class CheckUtil {

	private static final String token = "wxtoken";
	public static boolean checkSignature(String signature,String timestamp,String nonce){
		String[] str = new String[]{token,timestamp,nonce};
		//排序
		Arrays.sort(str);
		//拼接字符串
		StringBuffer buffer = new StringBuffer();
		for(int i =0 ;i<str.length;i++){
			buffer.append(str[i]);
		}
		//进行sha1加密
		String temp = SHA1.encode(buffer.toString());
		//与微信提供的signature进行匹对
		return signature.equals(temp);
	}

}
